Skip to content

Harden allOf merging and default-response handling#85

Merged
cubahno merged 3 commits into
mainfrom
ig/schema-merge
May 20, 2026
Merged

Harden allOf merging and default-response handling#85
cubahno merged 3 commits into
mainfrom
ig/schema-merge

Conversation

@cubahno

@cubahno cubahno commented May 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

A grab-bag of schema-composition fixes uncovered while generating against real-world specs.
The unifying theme: keep the generated types aligned with what strict response validators actually check, including in malformed but real corners.

  • Flattens allOf wrappers before the type-presence checks in mergeOpenapiSchemas. A nested allOf wrapper without its own type was being dropped by the len(t1) == 0 short-circuit, losing its properties.

  • Lets a parent type: object override a primitive allOf result (type: object, allOf: [SomeEnum]) - the outer object wins so the validator sees an object.

  • Merges colliding properties via mergePropertyProxies so enum / pattern / format constraints survive instead of being clobbered by the second declaration.

  • Merges array items from both branches (previously dropped, with downstream inference falling back to string).

  • Treats readOnly / writeOnly as annotations (OR-merge), not constraints that have to match per branch.

  • isDiscriminatedUnionWithChild: checks anyOf too, and return false when a discriminator+mapping describes an inheritance base rather than a union (no oneOf / anyOf).

  • When no explicit success is documented but default has content, treats default as 200 success. Fabricating a 204 struct{} made return content that didn't satisfy the real schema.

  • Preserves the declared ContentType on empty success bodies (e.g. text/html: {}) - strict validators rely on it.

  • Refactored shared logic into buildDefaultResponseDefinition.

@cubahno cubahno marked this pull request as ready for review May 20, 2026 19:09
@cubahno cubahno merged commit 3e0afd7 into main May 20, 2026
3 checks passed
@cubahno cubahno deleted the ig/schema-merge branch May 20, 2026 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant